<?php

class SEO {
	public static function customURLEncode($string) {
		//Lower case everything
		$string = strtolower($string);
		//Make alphanumeric (removes all other characters)
		$string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
		//Clean up multiple dashes or whitespaces
		$string = preg_replace("/[\s-]+/", " ", $string);
		//Convert whitespaces and underscore to dash
		$string = preg_replace("/[\s_]/", "-", $string);
		return $string;
	}
	
	public static function generateNewsURL( $id, $title, $status = Options::PAGE_NEWS_DETAILS_COMMENT_STATUS_VIEW ) {
		return URL::to('/')."/".Config::get('app.locale')."/news/".$id."/".self::customURLEncode($title )."/".$status;
	}
	
	public static function generateCategoryURL( $id, $title ) {
		return URL::to('/')."/".Config::get('app.locale')."/c-".$id."-".self::customURLEncode($title).".html";
	}
	
}